namespace QMVnSoft.Lists
{
    using QMVnSoft;
    using QMVnSoft.Controls;
    using QMVnSoft.DAL;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormDmPBTTCTLister : FormListLister
    {
        private IContainer components;

        public FormDmPBTTCTLister()
        {
            this.InitializeComponent();
        }

        public FormDmPBTTCTLister(object poUserDefined1, object poUserDefined2, object poUserDefined3) : base(poUserDefined1, poUserDefined2, poUserDefined3)
        {
            this.InitializeComponent();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            base.SuspendLayout();
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.ClientSize = new Size(0x31a, 0x214);
            base.LocalFieldCount = 0;
            base.LocalFieldName = "Stt";
            base.LocalTableName = "SPHANBO";
            base.Name = "FormDmPBTTCTLister";
            base.OrderFieldNames = "Stt";
            base.ShowDoneButton = true;
            base.ShowFreeFields = false;
            base.ShowMergeButton = false;
            this.Text = "Phân bổ chi phí công trình trực tiếp";
            base.UserLastKey = Keys.Tab;
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        public override bool OnAdd()
        {
            base.LocalFormEditor = new FormDmPBTTCTEditor(base.UserDefined1, base.UserDefined2, base.UserDefined3);
            return base.OnAdd();
        }

        public override void OnDone()
        {
            if ((((DateTime) base.UserDefined2) < AppInstance.OpeningDateOfSubEnterprice) || (((DateTime) base.UserDefined2) <= AppInstance.EndingDateOfSubEnterprice))
            {
                MessageBox.Show("Đã khóa dữ liệu!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else if ((base.LocalGridBrowser.SelectedRows.Count != 0) || (base.LocalTable.Rows.Count != 0))
            {
                FormPBGTCTFilter filter = new FormPBGTCTFilter();
                filter.Ngay_Ct1 = base.UserDefined1;
                filter.Ngay_Ct2 = base.UserDefined2;
                filter.ShowDialog();
                if (filter.CheckAccepted)
                {
                    base.UserDefined1 = filter.Ngay_Ct1;
                    base.UserDefined2 = filter.Ngay_Ct2;
                    DmPBCTDataAccess access = new DmPBCTDataAccess();
                    object obj2 = 0;
                    if (base.LocalGridBrowser.SelectedRows.Count != 0)
                    {
                        foreach (DataGridViewRow row in base.LocalGridBrowser.SelectedRows)
                        {
                            obj2 = ((DataRowView) row.DataBoundItem).Row["Stt"];
                            access.PhanBo_TTCT(AppInstance.Subsidiary, base.UserDefined1, base.UserDefined2, obj2, AppInstance.UserName);
                        }
                    }
                    else
                    {
                        obj2 = ((DataRowView) base.LocalGridBrowser.CurrentRow.DataBoundItem).Row["Stt"];
                        access.PhanBo_TTCT(AppInstance.Subsidiary, base.UserDefined1, base.UserDefined2, obj2, AppInstance.UserName);
                    }
                    base.OnDone();
                }
            }
        }

        public override bool OnEdit()
        {
            base.LocalFormEditor = new FormDmPBTTCTEditor(base.UserDefined1, base.UserDefined2, base.UserDefined3);
            return base.OnEdit();
        }

        public override void OnFillData()
        {
            object[][] objArray = new object[5][];
            object[] objArray2 = new object[4];
            objArray2[0] = "Tk_Di";
            objArray2[1] = "Tài khoản đi";
            objArray2[2] = "C";
            objArray[0] = objArray2;
            object[] objArray3 = new object[4];
            objArray3[0] = "Ten_Tk_Di";
            objArray3[1] = "Tên tài khoản đi";
            objArray3[2] = "C";
            objArray[1] = objArray3;
            object[] objArray4 = new object[4];
            objArray4[0] = "Dien_Giai";
            objArray4[1] = "Diễn giải";
            objArray4[2] = "C";
            objArray[2] = objArray4;
            object[] objArray5 = new object[4];
            objArray5[0] = "Ma_Sp";
            objArray5[1] = "Công trình";
            objArray5[2] = "C";
            objArray[3] = objArray5;
            object[] objArray6 = new object[4];
            objArray6[0] = "Tk_Den";
            objArray6[1] = "Tài khoản đến";
            objArray6[2] = "C";
            objArray[4] = objArray6;
            base.ColNames = objArray;
            base.OnFillData();
        }

        public override void OnRefresh()
        {
            base.LocalDataSet = new DmPBCTDataAccess().GetDataSet(AppInstance.Subsidiary, base.UserDefined3);
            base.OnRefresh();
        }
    }
}

